﻿public class VarAstTree : LuaAstTree
{
    public LuaVarReference Var { get; }
    public VarAstTree(LuaVarReference var)
    {
        Var = var;
        ResultType = var.StackType;
    }
    public override T GetResult<T>()
    {
        if (Var is T r)
            return r;
        return default;
    }
    public override void WriteTo(ICodeWriter writer)
    {
        writer.Code(Var.Name);
    }
    public override int GetHashCode()
    {
        return base.GetHashCode();
    }
    public override bool Equals(object? obj)
    {
        return obj is VarAstTree rhs && rhs.Var == this.Var;
    }
    public static bool operator !=(VarAstTree r, VarAstTree l)
    {
        return !r.Equals(l);
    }
    public static bool operator ==(VarAstTree r, VarAstTree l)
    {
        return r.Equals(l);
    }
}
